<?php 
		include_once "library/democrart/modules/product_model/vo/OrderModelQuadroOptionsAdmin.class.php";
		include_once "library/democrart/modules/product_model/vo/FilterModelQuadroOptionsByActiveAdmin.class.php";
		if(FALSE){$HttpResult = new HttpResult();}
		
		$HttpContentResult = $HttpResult->getHttpContentResult();
	  
	$head = new HtmlHeader(new HttpHeader());
		$head->addCSS('reset');
		$head->addCSS('print','', 'print');
		$head->addCSS('ie',  'css/ie', 'print',true);
		
		$head->addCSS('forum',"css/admin");		
		
		//<!-- PROGRAMACAO JS | JQUERY  -->
		$head->addJS(array('jquery', 'masked'));
		
    //MENU DROPDOWN
    $head->addJS('Menu principal','js/menu/ddsmoothmenu');
    $head->addCSS('Menu CSS','js/menu/ddsmoothmenu');
    
    //TINYMCE
    $head->addJS('tinymce','js/tinymce/jquery.tinymce');
    
    //FILEUPLOAD
    $head->addJS('so','js/uploadify/swfobject');
    $head->addJS('uploadify','js/uploadify/jquery.uploadify.v2.1.4.min');
    $head->addCSS('Upload CSS','js/uploadify/uploadify');

		//SLIDER SHOW
		$head->addJS('cycle', 'js/cycle/jquery.cycle.min');
	
		//<!-- JQUERY UI  -->
		$head->addJS('UI', 'js/UI/js/jquery-ui-1.8.6.custom.min');
		$head->addCSS('UI','js/UI/css/smoothness/jquery-ui-1.8.6.custom');
		
     //SELECTMENU
    $head->addJS('selectmenu','js/UI/development-bundle/ui/jquery.ui.selectmenu');
    $head->addCSS('selectmenu CSS','js/UI/css/jquery.ui.selectmenu');
    
    $head->addCSS('adminmenu','css/lista_produtos_admin');
    $head->addCSS('adminprodutos','css/produtos');
    
		//<!-- VTIP  -->
		$head->addJS('vtip', 'js/vtip/vtip');
		$head->addCSS('vtip', 'js/vtip/vtip');
		
		//<!-- TABLE SORTER -->
		$head->addJS('tablesorter', 'js/tablesorter/tablesorter');
		$head->addCSS('tablesorter', 'js/tablesorter/tablesorter');
    
    //<!-- PROGRAMACAO JS | JQUERY  -->
    $head->addJS(array('admin','admin_select', 'admin/product/product', 'admin/product/change_price_in_mass', 'democrart'));
			
$header_html = $head->show(TRUE);
$header_html = str_replace(array("democrart", "democrArt", "Democrart", "DemocrArt"), array("expressaoartistica", "Expressão Artística", "Expressão Artística", "Expressão Artística"), $header_html);
echo $header_html;
?>

<body>
<?php include Config::getFolderView("parts/admin/header.php"); ?>
<div id="main">
	
	<div id="blockActions" style="display: none;">
	</div>
	<span id="wait">Carregando aguarde...</span>
	
    <div id="main_content" class="quadro-list">
    	 
    	 <div id="box_left">
		
		<?php include "view/democrart/admin/product/quadro/menu.php" ?>
   	 
		 
		 </div>
		  		   
		  <div id="box_right">
		  		  	
		  	
		  	<a class="updateArrayItems" href="<?php echo Config::getRootPath("admin/product/quadro/tamanho/update_array_items")?>" ><img class="save-all" id="save_all" src="<?php echo Config::getAsset("assets/img/icons/save.png");?>" alt='Salvar tudo' title='Salvar todas as alterações' /></a>
		  			  			  	
		  	<div style='font-size: 10px;  margin: 10px 10px; color:gray '>
				<div id="breakcrumb" >
				<?php 
				//Debug::print_r($HttpMenuResult->arrayBreadCrumb);
				$totalBreads = count($HttpMenuResult->arrayBreadCrumb);
				if($totalBreads > 0){
					echo "Filtrado por: ";
					for($i = 0; $i < $totalBreads; $i++){
						$BreadCrumbInfoVO = $HttpMenuResult->arrayBreadCrumb[$i];
						if(FALSE){
							//apenas para o auto completar do eclipse
							$BreadCrumbInfoVO = new BreadCrumbInfoVO();
						}
						echo $BreadCrumbInfoVO->tittle;
						if($totalBreads > $i+1){
							echo " | ";
						}
					}
				}//end if $totalBreads > 0
				?>
				</div>
				<div>
					<?php
						if($HttpContentResult->count_total == 0):
							echo 'N&atilde;o foi encontrada nenhuma obra';
						else:
							echo  ( $HttpContentResult->count_total > 1 ? 'Foram encontradas' : 'Foi encontrada' ) . ": " .  $HttpContentResult->count_total .  ($HttpContentResult->count_total > 1 ? ' obras' : ' obra' ) ;  
						endif;
					?>
					&emsp;&emsp;&emsp;
						<?php OrderModelQuadroOptionsAdmin::showOrderBox(); ?>					  
					&emsp;&emsp;&emsp;
						<?php FilterModelQuadroOptionsByActiveAdmin::showOrderBox(); ?>					  
 				</div>
			</div>
			
			<div class="massa">
		  		<h1>Alterar pre&ccedil;o em massa para o filtro atual:</h1>
		  		<form action="" method="post" id="alt_massa_price">
		  			Tipo de operação:
					<input id="value" type="radio" value="value" name="action_type" /><label for='value'>R$</label>
					<input id="percent" type="radio" checked="checked" value="percent" name="action_type" /><label for='percent'>%</label>
					| subtrair ou adicionar?
					<input id="more" type="radio" value="more" name="signal" /><label for='more'>+</label>
					<input id="less" type="radio" checked="checked" value="less" name="signal" /><label for='less'>-</label>
					<div id="price">
						<label for="mass_magnitude">Valor:</label>
						<input type="text" id="mass_magnitude" name="val" class="price" />
						<span class="btn" id="btnAltPriceAll">Alterar</span>  
					</div>			
		  		</form>
		  		
		  	</div>
		  		<ul id="search">
		  			<li><label for="product_search">Pesquisa:</label></li>
		  			<li><input type="text" id="product_search" name="search" /></li>
		  			<li><a href="<?php echo Config::getRootPath("admin/product/quadro/search.") ?>" onclick="this.href = this.href + $('#product_search').val();" class="btn" id="btnSearch">Ok</a></li>
		  		</ul>
	
			<!-- QUADROS DE EXIBICAO DOS PRODUTOS -->
			<div style="display:block;clear:both;margin-top: -4px;">
			
			<?php
				
				$i = 0;
//				print_r($HttpContentResult->arrayProducts);
				foreach($HttpContentResult->arrayProducts as $product){
					
					
					$i++;
					$margem = "";
					if($i==3){
						$i = 0;
						$margem = "style=\"margin-right:0\"";
					}
					
					if($product->quadro_width > $product->quadro_height){
						$classThumb = "paisagem";
					}else if($product->quadro_width < $product->quadro_height){
						$classThumb = "retrato";
					}else{
						$classThumb = "quadrado";
					}
					$debug_prod = new stdClass();
					$debug_prod->composition 		=  $product->quadro_composition_name;
					$debug_prod->quadro_technique 	=  $product->quadro_technique_name;
					$debug_prod->quadro_format 		=  $product->quadro_format_name;
					$debug_prod->quadro_theme 		=  $product->quadro_theme_name;
					$debug_prod->quadro_style 		=  $product->quadro_style_name;
					$debug_prod->artist_name 		=  $product->quadro_artist_name;
					$debug_prod->cores 				=  array();
					//Debug::print_r($product->color);
					
					if(count($product->color) > 0 ){
						foreach($product->color as  $temp_color){
							if(isset($temp_color->image[0]) && is_object($temp_color->image[0]))
							$debug_prod->cores[] = $temp_color->image[0]->name;
						}
					}
					$debug_text = print_r($debug_prod, TRUE);
					$debug_text = str_replace("
", "\\n", $debug_text);
					
//				$path_img = $product->quadro_image_path;
				//$thumb = Config::getAsset("assets/$path_img");
				//$img = Config::getAsset("assets/" . str_replace('/thumb','', $path_img));
				$product_model_id = $product->id;
				$thumb 		= Config::getRootPath("image/get_image/product_id.$product_model_id/max_width.130/max_height.130/");
				$img 		= Config::getRootPath("image/get_image/product_id.$product_model_id/md.1/max_width.770/max_height.500/");//Config::getImagePath(str_replace('/thumb','', $path_img));
				
				$product_desc = strlen($product->name) > 30 ? substr($product->name, 0,25) . "..." : $product->name;
				$info = $product_desc != $product->name ? "title=\"$product->name\" class=\"vtip\"" : ""; 
				
				$details_url = "http://".Navigation::getURIDomain()."/".Config::getRootApplication()."/admin/product/quadro/detail/product.".$product->product_model_democrart_quadro_id;
				$artist_url = Config::getRootPath("artist/detail/artista." .  $product->quadro_artist_id ."/". $product->quadro_artist_name) ; 
//				$thumb 		= Config::getImagePath($path_img);
//				$img 		= Config::getImagePath(str_replace('/thumb','', $path_img));
				$box_class = ($product->active) ? "" : "inative";
			?>
									
			<div class="boxProdutos <?php echo $box_class ?>" <?php echo $margem ?>>
				
				<a href="<?php echo $details_url; ?>"><img  class="thumb <?php echo $classThumb?>" src="<?php echo $thumb . $product->id . ".jpg" ; ?>" alt="<?php echo  $product->name?>" title="<?php echo  DataHandler::cropString($product->name, 31); ?>" /></a>
				
				<ul class="product_info">
					<li>
						<h1><?php echo  $product->quadro_type_name . " - <span>" . $product->quadro_artist_name ?> </span></h1>
					</li>
					<li>
						<h1>
						<?php if($product->active == 0){ ?>
								<a href="#" class="deleteProductModel" id="<?php echo $product->product_model_id ?>">Excluir</a>
						<?php }	?>
						</h1>
					</li>
					<li>
						<h2><?php echo  $product_desc; ?></h2>
					</li>
					<li>
						<?php echo  ($product->quadro_type_name); ?>
					</li>
					<li>
						<?php echo  ($product->active)?"Publicado":"NÃO PUBLICADO"; ?>
					</li>
					</li>
				</ul>
							<table class="tablesorter clear">
								<thead>
									<tr>
										<th>Status</th>
										<th>SKU</th>
										<th>Material</th>
										<th>Dimens&otilde;es</th>
										<th>Preço</th>
										<th class="ico">Ação</th>
									</tr>
								</thead>
								<tbody>
									<?php
										/**
				 * [0] => stdClass Object(
				            [product_model_democrart_quadro_id] => 18
				            [product] => Array  (
				                    [0] => stdClass Object
				                        (
				                            [id] => 45
				                            [active] => 1
				                            [product_model_id] => 18
				                            [name] => Dedalo sobe a parede
				                            [description] => 
				                            [price] => 407.5900
				                            [sku] => 269195710-76-18
				                            [stock] => 359
				                            [drawing] => 360
				                            [view] => 
				                            [date_insert] => 2010-12-20 18:21:09
				                            [date_update] => 2010-12-20 18:21:09
				                            [order] => 1
				                            [hit] => 
				                            [product_democrart_quadro_id] => 45
				                            [width] => 50.00
				                            [height] => 45.00
				                            [material_id] => 1
				                            [product_model_name] => Dedalo sobe a parede
				                            [material_name] => Papel algod�o
				                        )
				 * 						
										 								 * 
										
																				 *  
				 */						
				 						$icon_on = Config::getImagePath("icons/on.gif");
										$icon_off = Config::getImagePath("icons/off.gif");
										
				 						if(!isset($product->product)){
				 						 $product->product = array();
				 						}
										foreach($product->product as $itemProduto){
											$active 	=  $itemProduto->active;
											if($active > -1){
												$sku 		=  $itemProduto->sku;
												$material 	=  $itemProduto->material_name;
												$tamanho 	= $itemProduto->height . " x " . $itemProduto->width;	
												$price 		= DataHandler::convertMoneyToBrazil($itemProduto->price); 
												$price 		= str_replace("R$","", $price);

									?>
									<tr>
										<td class="ico one"><img src="<?php echo ($active)?"$icon_on":"$icon_off"; ?>" alt="" title="" /></td>
										<td><?php echo $sku ?></td>
										<td><?php echo $material ?></td>
										<td><?php echo $tamanho ?></td>
										<td><input type="text" class="price" name="price" value="<?php echo $price ?>" id="price<?php echo $itemProduto->id ?>" /></td>
										<td class="ico two" >
											<a class="updateItem" id="<?php echo $itemProduto->id ?>" href="<?php echo Config::getRootPath("admin/product/quadro/tamanho/update_item")?>" >
												<img id="edit1" src="<?php echo Config::getAsset("assets/img/icons/save.jpg");?>" alt="Editar" title="" />
											</a>
											<?php if($active > 0){?>
											<a class="unpublicItem" id="<?php echo $itemProduto->id ?>" href="javascript:void(0);" >
												<img id="del-<?php echo $product->id ?>" src="<?php echo Config::getAsset("assets/img/icons/delete.jpg");?>" alt="Excluir" title="" />
											</a>
											<?php } else { ?>
											<a class="publicItem" id="<?php echo $itemProduto->id ?>" href="javascript:void(0);" >
												<img id="del-<?php echo $product->id ?>" src="<?php echo Config::getAsset("assets/img/icons/v.jpg");?>" alt="Excluir" title="" />
											</a>
											<?php } ?>
										</td>
									</tr>
									
										<?php }//end if active ?>
									<?php } ?>
									
								</tbody>
							</table>
			</div>
			<?php }?>
			</div>		
			<!-- FIM DO QUADRO -->
			
			<!-- COMECO PAGINACAO -->
			<div style="clear: both;"></div>
			<div id="model-pagination" style="text-align: center;padding: 20px 0px 20px 0px;">
			<?php 
				include_once("library/facil3/utils/Pagination.class.php");
				$Pagination = new Pagination($HttpContentResult->page, $HttpContentResult->limit_page, $HttpContentResult->count_total);
				$htmlPaginacao = $Pagination->getHtml();
				echo $htmlPaginacao;
			?>
			
			</div>
		   </div>
    	  
    </div>
    
</div>

<?php  include Config::getFolderView("parts/admin/footer.php"); ?>

</body>
</html>
